
export default {
	namespaced:true,
	state: {
		address:[],
	},
	getters: {
		getList:state=>{
			return state.address;
		},
		getByisCheck:state =>{
		 let obj = state.address.find(item => item.isCheck)
			if(obj == undefined){
				return obj = {
					id:0,
					isCheck:false,
					name:'',
					phone:'',
					region:'',
					regionText:'',
					address:'',
				};
			}
			return obj;
		}
	},
	mutations: {
		add(state,addr){
			state.address.push(addr);
		},
		del(state,id){
			let i = state.address.findIndex(item => item.id == id);
			state.address.splice(i,1);
		},
		update(state,addr){
			let i = state.address.findIndex(item => item.id == addr.id);
			state.address[i] = addr;
			state.address.forEach((item)=>{
				if(item.id != addr.id){
					item.isCheck = false;
					
				}
			})
		}
	},
	actions: {
		addAddr({state,commit},addr){
			commit('add',addr);
		},
		delAddr({state,commit},id){
			commit('del',id);
		},
		updateAddr({state,commit},addr){
			commit('update',addr)
		}
	}
}